package com.example.entity;


import io.swagger.annotations.ApiModelProperty;

import java.util.Date;

public class ResBody<T> {
    @ApiModelProperty("状态")
    private String status;
    @ApiModelProperty("消息")
    private String msg;
    @ApiModelProperty("数据")
    private T data;
    @ApiModelProperty("异常信息")
    private String error;
    private Integer notFlushModified = 0;
    private Long timestamp = (new Date()).getTime();



    public ResBody(CommonEnum commonEnum) {
        this.status = commonEnum.getStatus();
        this.msg = commonEnum.getMsg();
        this.error = commonEnum.getError();
    }

    public ResBody(CommonEnum commonEnum, T data) {
        this.error = commonEnum.getError();
        this.status = commonEnum.getStatus();
        this.msg = commonEnum.getMsg();
        this.data = data;
    }

    public ResBody(CommonEnum commonEnum, String msg) {
        this.error = commonEnum.getError();
        this.status = commonEnum.getStatus();
        this.msg = msg;
    }



    public ResBody(String status, String msg, T data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public ResBody(String status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    public ResBody(String status, String msg, String error) {
        this.status = status;
        this.msg = msg;
        this.error = error;
    }

    public static <K> ResBody<K> success(K k) {
        return new ResBody(CommonEnum.SUCCESS, k);
    }

    public static <K> ResBody<K> error(String msg) {
        return new ResBody(CommonEnum.INTERNAL_SERVER_ERROR, msg);
    }

    public static ResBody success() {
        return new ResBody(CommonEnum.SUCCESS);
    }

    public static ResBody error() {
        return new ResBody(CommonEnum.INTERNAL_SERVER_ERROR);
    }

    public static ResBody error(CommonEnum res) {
        return new ResBody(res.getStatus(), res.getMsg(), res.getError());
    }



    public String getStatus() {
        return this.status;
    }

    public String getMsg() {
        return this.msg;
    }

    public T getData() {
        return this.data;
    }

    public String getError() {
        return this.error;
    }

    public Integer getNotFlushModified() {
        return this.notFlushModified;
    }

    public Long getTimestamp() {
        return this.timestamp;
    }

    public void setStatus(final String status) {
        this.status = status;
    }

    public void setMsg(final String msg) {
        this.msg = msg;
    }

    public void setData(final T data) {
        this.data = data;
    }

    public void setError(final String error) {
        this.error = error;
    }

    public void setNotFlushModified(final Integer notFlushModified) {
        this.notFlushModified = notFlushModified;
    }

    public void setTimestamp(final Long timestamp) {
        this.timestamp = timestamp;
    }

    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof ResBody)) {
            return false;
        } else {
            ResBody<?> other = (ResBody)o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                Object this$status = this.getStatus();
                Object other$status = other.getStatus();
                if (this$status == null) {
                    if (other$status != null) {
                        return false;
                    }
                } else if (!this$status.equals(other$status)) {
                    return false;
                }

                Object this$msg = this.getMsg();
                Object other$msg = other.getMsg();
                if (this$msg == null) {
                    if (other$msg != null) {
                        return false;
                    }
                } else if (!this$msg.equals(other$msg)) {
                    return false;
                }

                Object this$data = this.getData();
                Object other$data = other.getData();
                if (this$data == null) {
                    if (other$data != null) {
                        return false;
                    }
                } else if (!this$data.equals(other$data)) {
                    return false;
                }

                label62: {
                    Object this$error = this.getError();
                    Object other$error = other.getError();
                    if (this$error == null) {
                        if (other$error == null) {
                            break label62;
                        }
                    } else if (this$error.equals(other$error)) {
                        break label62;
                    }

                    return false;
                }

                label55: {
                    Object this$notFlushModified = this.getNotFlushModified();
                    Object other$notFlushModified = other.getNotFlushModified();
                    if (this$notFlushModified == null) {
                        if (other$notFlushModified == null) {
                            break label55;
                        }
                    } else if (this$notFlushModified.equals(other$notFlushModified)) {
                        break label55;
                    }

                    return false;
                }

                Object this$timestamp = this.getTimestamp();
                Object other$timestamp = other.getTimestamp();
                if (this$timestamp == null) {
                    if (other$timestamp != null) {
                        return false;
                    }
                } else if (!this$timestamp.equals(other$timestamp)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(final Object other) {
        return other instanceof ResBody;
    }



    public String toString() {
        return "ResBody(status=" + this.getStatus() + ", msg=" + this.getMsg() + ", data=" + this.getData() + ", error=" + this.getError() + ", notFlushModified=" + this.getNotFlushModified() + ", timestamp=" + this.getTimestamp() + ")";
    }

    public ResBody() {
    }
}
